package jsyf.oa.web.wechat.service_account.controller;


import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.wechat.service_account.WechatUserFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(value = "服务号-获取用户列表", description = "服务号-获取用户列表")
@Controller
@RequestMapping(value = "/wechatServiceAccountUser")
public class WechatUserController {


    @Resource
    private WechatUserFacade wechatUserFacade;
    /**
     * 服务号-获取用户列表
     */
    @ApiOperation(
            value = "服务号-获取用户列表",
            notes = "服务号-获取用户列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    @RequestMapping(value = "/getUserList.json", method = RequestMethod.POST)
    public void getUserList(HttpServletResponse response, @RequestBody String jsonData) {

        JSONObject jsonObject = (JSONObject) JSONObject.parse(jsonData);
        int requestPage = jsonObject.getInteger("requestPage");
        int pageSize = jsonObject.getInteger("pageSize");
        JSONObject users = wechatUserFacade.getUserByPage(jsonObject, requestPage, pageSize);
        if (users != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(users));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
}